package org.blade.personal.framework.dsl.sql;

import org.blade.personal.framework.orm.EntityAlias;
import org.blade.personal.framework.orm.TypeAlias;
import org.blade.personal.framework.session.ResultHandler;

/**
 * SQL子句，由于不同的数据库有不同的方言， 这里需要实现几个版本的子句
 * 
 * @author ZGF
 *
 * @version 0.1
 */
public interface Sql {

	/**
	 * Select
	 * 
	 * @param alies
	 * @return
	 */
	public Sql select(TypeAlias... alies);

	/**
	 * from
	 * 
	 * @param entity
	 * @return
	 */
	public Sql from(EntityAlias entity);

	/**
	 * where
	 * 
	 * @param alies
	 * @return
	 */
	public Sql where(TypeAlias... alies);

	/**
	 * and
	 * 
	 * @param alies
	 * @return
	 */
	public Sql and(TypeAlias alies);

	/**
	 * from
	 * 
	 * @param clause
	 * @return
	 */
	public Sql from(Sql clause);

	/**
	 * list
	 * 
	 * @param alies
	 * @return
	 */

	public Sql list(TypeAlias... alies);

	/**
	 * limit
	 * 
	 * @param max
	 * @return
	 */
	public Sql limit(Integer max);

	/**
	 * union
	 * 
	 * @param clause
	 * @return
	 */
	public Sql union(Sql clause);

	/**
	 * union all
	 * 
	 * @param clause
	 * @return
	 */
	public Sql unionAll(Sql clause);

	/**
	 * Get the SQL
	 * 
	 * @return
	 */
	public String get();

	/**
	 * 获取别名
	 * 
	 * @return
	 */
	public String getAlise();

	/**
	 * join
	 * 
	 * @return
	 */
	public Sql join(Sql sql);

	/**
	 * join
	 * 
	 * @param entity
	 *            实体别名
	 * @return
	 */
	public Sql join(EntityAlias entity);

	/**
	 * left join
	 * 
	 * @param entity
	 * @return
	 */
	public Sql leftJoin(EntityAlias entity);

	/**
	 * left join
	 * 
	 * @param sql
	 * @return
	 */
	public Sql leftJoin(Sql sql);

	/**
	 * right join
	 * 
	 * @param sql
	 * @return
	 */
	public Sql rightJoin(Sql sql);

	/**
	 * right join
	 * 
	 * @param entity
	 *            实体
	 * @return
	 */
	public Sql rightJoin(EntityAlias entity);

	/**
	 * on
	 * 
	 * @param alies
	 * @return
	 */
	public Sql on(TypeAlias... alies);

	/**
	 * group by
	 * 
	 * @param alies
	 * @return
	 */
	public Sql groupBy(TypeAlias... alies);

	/**
	 * order by
	 * 
	 * @param alies
	 * @return
	 */
	public Sql orderBy(TypeAlias... alies);

	/**
	 * having
	 * 
	 * @return
	 */
	public Sql having(TypeAlias alies);

	/**
	 * 获取查结果集
	 * 
	 * @param rs
	 * @return
	 */
	public TypeAlias $(String rs);

	/**
	 * 获取结果集辅助器
	 * @return
	 */
	public ResultHandler getResultHandler();

}
